/**
 * checking account class, extends the abstract 
 * parent class Account.
 * @author Kristopher Gooding/Kyle Scharnhorst
 * @version 4/25/2014
 */
public class CheckingAccount extends Account {
	/**boolean representing the debit status of the checking account.*/
	private boolean my_debit_allowed;
	/**current debit amount in the checking account.*/
	private double my_debit_amount;
	/**debit rate.*/
	private static double my_debit_rate = 4.7;
	/**credit card for this account.*/
	private static CreditCard my_credit_card;
	/**savings account linked to this checking account.*/
	private static SavingsAccount my_savings_account;
	/**debit card attached to this checking account.*/
	private static DebitCard my_debit_card;

	/**
	 * checking account constructor for account with no debit.
	 * @param the_name
	 * @param the_street
	 * @param the_zip_code
	 * @param the_town
	 * @param the_country
	 */
	public CheckingAccount(final String the_name, final String the_street,
			final String the_zip_code, final String the_town,
			final String the_country) {
		super(the_name, the_street, the_zip_code, the_town, the_country);
		my_account_number = my_next_account_number;
		my_next_account_number++;
		my_debit_allowed = false;
		my_debit_amount = 0;
	}

	/**
	 * checking account constructor for account with debit.
	 * @param the_name
	 * @param the_street
	 * @param the_zip_code
	 * @param the_town
	 * @param the_country
	 * @param the_debit
	 */
	public CheckingAccount(final String the_name, final String the_street,
			final String the_zip_code, final String the_town,
			final String the_country, final float the_debit) {
		super(the_name, the_street, the_zip_code, the_town, the_country,
				the_debit);
		my_account_number = my_next_account_number;
		my_next_account_number++;
		my_debit_allowed = true;
		my_debit_amount = the_debit;
	}

	/**
	 * simple testing constructor.
	 * @param the_account_number
	 */
	public CheckingAccount(final int the_account_number) {
		super(the_account_number);
		my_account_number = the_account_number;
	}

	/**
	 * cost of maintaining the account.
	 */
	public void determineCosts() {
		my_balance = my_balance - my_cost;
		if (my_balance < 0) {
			my_balance = my_balance - (my_balance * my_debit_rate / 100);
		}
	}

	/**
	 * method used to withdraw money from the account.
	 * @param the_amount
	 * @return transaction success or failure.
	 */
	public boolean withdrawal(final double the_amount) {
		if (((my_balance - the_amount) < 0) && (!my_debit_allowed)) {
			return false;
		} else if ((my_balance - the_amount) < -my_debit_amount) {
			my_balance = my_balance - the_amount;
			return true;
		} else {
			return false;
		}
	}

	/**
	 * method to transfer money into the account.
	 * @param the_amount
	 */
	public void verseMoney(final double the_amount) {
		my_balance += the_amount;
	}

	/**
	 * method used to apply for a credit card out of this account.
	 * @param the_name
	 * @param the_street
	 * @param the_zip_code
	 * @param the_town
	 * @param the_country
	 * @param the_account_number
	 * @return
	 */
	public boolean applyForCreditCard(final String the_name,
			final String the_street, final String the_zip_code,
			final String the_town, final String the_country,
			final int the_account_number) {
		if (my_balance < 0) {
			return false;
		}
		if (my_balance <= 2500) {
			my_credit_card = new CreditCard(the_name, the_street, the_town,
					the_zip_code, the_country);
		} else {
			my_credit_card = new CreditCard(the_name, the_street, the_town,
					the_zip_code, the_country, 5000);
		}
		return true;
	}

	/**
	 * @return my_balance
	 */
	public double getBalance() {
		return my_balance;
	}

	/**
	 * method to increase the balance of the account.
	 * @param the_amount
	 */
	public void increaseBalance(final double the_amount) {
		my_balance += the_amount;
	}

	/**
	 * method to decrease the balance of the account.
	 * @param the_amount
	 */
	public void decreaseBalance(final double the_amount) {
		my_balance -= the_amount;
	}

	/**
	 * @return my_debit_amount
	 */
	public double getDebitAmount() {
		return my_debit_amount;
	}

	/**
	 * sets the balance of the account to the given number.
	 * @param the_amount
	 */
	public void setBalance(final double the_amount) {
		my_balance = the_amount;
	}

	/**
	 * Comparator for the checking account class.
	 * @return returns true if this account and the other
	 * are the same account.
	 */
	public boolean equals(final Object o) {
		if (my_account_number == ((CheckingAccount) o).my_account_number)
			return true;
		else
			return false;

	}


}
